package com.ruoyi.web.controller.portal;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.portal.domain.PorNewsType;
import com.ruoyi.portal.service.IPorNewsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻类型Controller
 * 
 * @author cjie
 * @date 2021-05-09
 */
@RestController
@RequestMapping("/portal/type")
public class PorNewsTypeController extends BaseController {
    @Autowired
    private IPorNewsTypeService porNewsTypeService;

    /**
     * 查询新闻类型列表
     */
    @PreAuthorize("@ss.hasPermi('portal:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(PorNewsType porNewsType) {
        startPage();
        List<PorNewsType> list = porNewsTypeService.selectPorNewsTypeList(porNewsType);
        return getDataTable(list);
    }

    /**
     * 导出新闻类型列表
     */
    @PreAuthorize("@ss.hasPermi('portal:type:export')")
    @Log(title = "新闻类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PorNewsType porNewsType) {
        List<PorNewsType> list = porNewsTypeService.selectPorNewsTypeList(porNewsType);
        ExcelUtil<PorNewsType> util = new ExcelUtil<PorNewsType>(PorNewsType.class);
        return util.exportExcel(list, "新闻类型数据");
    }

    /**
     * 获取新闻类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('portal:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(porNewsTypeService.selectPorNewsTypeById(id));
    }

    /**
     * 新增新闻类型
     */
    @PreAuthorize("@ss.hasPermi('portal:type:add')")
    @Log(title = "新闻类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PorNewsType porNewsType) {
        return toAjax(porNewsTypeService.insertPorNewsType(porNewsType));
    }

    /**
     * 修改新闻类型
     */
    @PreAuthorize("@ss.hasPermi('portal:type:edit')")
    @Log(title = "新闻类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PorNewsType porNewsType) {
        return toAjax(porNewsTypeService.updatePorNewsType(porNewsType));
    }

    /**
     * 删除新闻类型
     */
    @PreAuthorize("@ss.hasPermi('portal:type:remove')")
    @Log(title = "新闻类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(porNewsTypeService.deletePorNewsTypeByIds(ids));
    }
}
